package com.weasel.weixin.mp;

import com.weasel.weixin.commons.menu.MenuRequest;
import com.weasel.weixin.commons.menu.MenuResponse;
import com.weasel.weixin.commons.menu.bean.Menu;
import com.weasel.weixin.commons.menu.builder.*;
import com.weasel.weixin.mp.builder.MpConfigBuilder;
import com.weasel.weixin.mp.config.MpConfig;
import com.weasel.weixin.mp.request.MpMenuRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

/**自定义菜单测试
 * 运行main方法，通过注释和打开注释来测试各方法
 * Created by Dylan on 2015/9/29.
 */
public class MenuRequestDemo {

    public static void main(String [] args) throws IOException, ExecutionException {

        MpConfig config = MpConfigBuilder.fromXML("classpath:weixin-config.xml");

        MenuRequest request = new MpMenuRequest(config);

        create(request);
        //get(request);
        //delete(request);

    }

    public static void get(MenuRequest request) throws IOException, ExecutionException {

        MenuResponse response = request.get();

        System.out.print(response);
    }

    public static void delete(MenuRequest request) throws IOException, ExecutionException {

        MenuResponse response = request.delete();

        System.out.print(response);
    }

    public static void create(MenuRequest request) throws IOException, ExecutionException {

       Menu menu = MenuBuilders.create()
                                .button(new ViewButtonBuilder().name("首页")
                                                               .url("http://yhwemall.ngrok.jlw365.com")
                                )
                                .button(new CommonButtonBuilder().name("优惠")
                                                                 .button(new ViewButtonBuilder().name("双十二")
                                                                                                .url("http://www.jlw365.com")
                                                                 ).button(new ScancodePushButtonBuilder().name("分享")
                                                                                                         .key("uhui_scancode")
                                                                )
                                )
                                .button(new CommonButtonBuilder().name("我的")
                                                                 .button(new ClickButtonBuilder().name("订单")
                                                                                                 .key("my_order")
                                                                 ).button(new ClickButtonBuilder().name("积分")
                                                                                                  .key("my_score")
                                                                 )
                                )
                                .build();

        MenuResponse response = request.create(menu);

        System.out.println(response);
    }
}
